﻿/*
 * Created by SharpDevelop.
 * User: Chris
 * Date: 6/13/2013
 * Time: 9:38 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Project;

namespace Dither.Xna.Bindings.Project
{
	/// <summary>
	/// Description of XnaContentFileProjectItem.
	/// </summary>
	public class XnaContentFileProjectItem : FileProjectItem 
	{
		const string NameNode = "Name";
		const string ProcessorNode = "Processor";
		const string ImporterNode = "Importer";
		
		const string AssetNameProperty = "AssetName";
		const string ProcessorProperty = "Processor";
		const string ImporterProperty = "Importer";
		
		IProjectItemBackendStore backendStore;
		
        public string AssetName 
        { 
        	get 
        	{ 
        		string returnValue = _GetMetadata(NameNode);
        		
        		if (string.IsNullOrEmpty(returnValue))
        		{
        			ResetAssetNameValue();
        			returnValue = _GetMetadata(NameNode);
        		}
        		
        		return returnValue;
        	}
        	set { _SetMetadata(NameNode, value); }
        }
        
//        public string Importer
//        {
//        	get 
//        	{
//        		string returnValue = _GetMetadata(ImporterNode);
//        		
//        		if (string.IsNullOrEmpty(returnValue))
//        		{
//        			ResetImporterValue();
//        			returnValue = _GetMetadata(ImporterNode);
//        		}
//        		
//        		return returnValue;
//        	}
//        	set {_SetMetadata(ImporterNode, value); }
//        }
//        
//        public string Processor
//        {
//        	get 
//        	{
//        		string returnValue = _GetMetadata(ProcessorNode);
//        		
//        		if (string.IsNullOrEmpty(returnValue))
//        		{
//        			ResetProcessorValue();
//        			returnValue = _GetMetadata(ProcessorNode);
//        		}
//        		
//        		return returnValue;
//        	}
//        	set { _SetMetadata(ProcessorNode, value); }
//        }

		public XnaContentFileProjectItem(IProjectItemBackendStore item)
			: base(item.Project, item.ItemType, item.EvaluatedInclude)
		{
			backendStore = item;
		}
		
		private void _SetMetadata(string metaDataName, string value)
		{
			backendStore.SetMetadata(metaDataName, value);
		}
		
		private string _GetMetadata(string metaDataName)
		{	
			return backendStore.GetMetadata(metaDataName);
		}
		
		public override void InformSetValue(System.ComponentModel.PropertyDescriptor propertyDescriptor, object component, object value)
		{
			string valueString = (string)value;
			
			if (string.IsNullOrEmpty(valueString))
			{
				switch (propertyDescriptor.Name) {
					case AssetNameProperty:
						ResetAssetNameValue();
						break;
					case ImporterProperty:
						ResetImporterValue();
						break;
					case ProcessorProperty:
						ResetProcessorValue();
						break;
				}
			}
			
			base.InformSetValue(propertyDescriptor, component, value);
		}
		
		private void ResetAssetNameValue()
		{
			AssetName = System.IO.Path.GetFileNameWithoutExtension(this.FileName);
		}
		
		private void ResetProcessorValue()
		{
			throw new NotImplementedException();
		}
		
		private void ResetImporterValue()
		{
			throw new NotImplementedException();
		}
	}
}
